package com.zhixiu.app.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域配置
 * 
 * @author administrator
 * @date Jan 12, 2019
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry
		        // 允许跨域访问的路径
		        .addMapping("/**")
		        // 允许跨域访问的源
		        .allowedOrigins("*")
		        // 允许请求方法
		        .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
		        // 预检间隔时间
		        .maxAge(168000)
		        // 允许头部设置
		        .allowedHeaders("*")
		        // 是否发送cookie
		        .allowCredentials(true);
	}
}